#!/bin/bash
# env
yum -y install unzip zip vim git wget dos2unix
if [  $# = 1 ];then
rm -rf Makefile1.7 Makefile
#download bcg729
if [ $1 = '1' ] ; then
wget http://hk-area1-file.oss-cn-hongkong.aliyuncs.com/downloads/g729/bcg729/Makefile1.7
mv Makefile1.7 Makefile
else
wget http://hk-area1-file.oss-cn-hongkong.aliyuncs.com/downloads/g729/bcg729/Makefile
fi
rm -rf bcg729.zip
rm -rf mod_bcg729.c
wget http://hk-area1-file.oss-cn-hongkong.aliyuncs.com/downloads/g729/bcg729/bcg729.zip
wget http://hk-area1-file.oss-cn-hongkong.aliyuncs.com/downloads/g729/bcg729/mod_bcg729.c
dos2unix Makefile
dos2unix mod_bcg729.c
#unzip -o bcg729.zip
make 
make install
#vim /usr/local/freeswitch/conf/autoload_configs/modules.conf.xml
sed -i "/g729/d"  /usr/local/freeswitch/conf/autoload_configs/modules.conf.xml
sed -i "s/<\/modules>/<load module=\"mod_bcg729\"\/>\\n<\/modules>/g"   /usr/local/freeswitch/conf/autoload_configs/modules.conf.xml
rm -rf Makefile1.7 Makefile
rm -rf bcg729*
rm -rf mod_bcg*
/usr/local/freeswitch/bin/fs_cli -x "reload mod_bcg729"
else
echo -e "\033[31;49;1m [ERROR: plese give the params==0/1] please try again !\033[39;49;0m"
echo -e "\033[32;49;1m if the freeswitch version ≥ 1.7 ,please use command : sh $0 1 \033[39;49;0m"
echo "sh $0 1"
echo -e "\033[32;49;1m if the freeswitch version < 1.7 ,please use command : sh $0 0 \033[39;49;0m"
fi
#restart freeswitch
